package com.lihepeng.leecode.heap;

public class Heap {
    private Node[] heapArray;
    private int maxSize;
    private int currentSize;

    public Heap(int mx) {
        this.maxSize = mx;
        this.heapArray = new Node[maxSize];
        this.currentSize = 0;
    }

    public boolean isEmpty() {
        return this.currentSize == 0;
    }

    public boolean isFull() {
        return this.currentSize == this.maxSize;
    }

    public boolean insert(int key) {
        if (isFull()) {
            return false;
        }
        Node newNode = new Node(key);
        heapArray[currentSize] = newNode;
        trickleUp(currentSize++);
        return true;
    }
    // 向上调整
    // 直到父节点小于当前节点

    public void trickleUp(int index) {
        // 父节点的索引
        int parent = (index - 1) / 2;
        Node buttomNode = heapArray[index];
        while (index > 0 && heapArray[parent].val < buttomNode.val) {
            // 父节点赋值给当前节点
            heapArray[index] = heapArray[parent];
            index = parent;
            parent = (parent - 1) / 2;
        }
        heapArray[index] = buttomNode;
    }

    // 向下调整
    public void trickDown(int index) {
        Node top = heapArray[index];
        while (index < currentSize / 2) {
            int leftChildIndex = index * 2 + 1;
            int rightChildIndex = leftChildIndex + 1;


        }
    }

    // 删除节点
    public void removeNode() {

    }


    private static class Node {
        private int val;
        private Node leftNode;
        private Node rightNode;

        public Node(int val) {
            this.val = val;
        }
    }
}
